#pragma once

#include <sys/epoll.h>
#include "Log.hpp"
#include "Common.hpp"

using namespace LogModule;

class Epoller
{
public:
    Epoller() : _epfd(-1)
    {
        _epfd = epoll_create(256);
        if (_epfd < 0)
        {
            LOG(LogLevel::FATAL) << "epoll_create error";
            exit(EPOLL_CREATE_ERR);
        }
        LOG(LogLevel::INFO) << "epoll_create success, fd: " << _epfd;
    }
    void ADDEvent(int fd, uint32_t events)
    {
        struct epoll_event event;
        event.data.fd = fd;
        event.events = events;
        int n = epoll_ctl(_epfd, EPOLL_CTL_ADD, fd, &event);
        if (n < 0)
        {
            LOG(LogLevel::WARNING) << "epoll_ctl ADD error";
            return;
        }
        LOG(LogLevel::INFO) << "epoll_ctl ADD success, fd: " << fd;
    }
    void MODEvent()
    {
    }
    void DELEvent()
    {
    }
    void Wait()
    {
    }
    ~Epoller()
    {
    }

private:
    int _epfd;
};